<!DOCTYPE>
<html>
@include('common.head')
<body>
	<!--header-->
	@include('common.navbar')
	<!-- header end -->
	<meta name="csrf-token" content="{{ csrf_token() }}">
	<div class="page-container">
		<div class="page-content" id="mainContents">
			<div class="container-fluid">
				<div class="row-fluid clearfix">
					<!-- BEGIN STYLE CUSTOMIZER -->
					<div class="span12">
						<h3 class="page-title"> 新增订单  </h3>
						<ul class="breadcrumb">
							<li> <i class="icon-home"></i> <a href="index.html">首页</a> <i class="icon-angle-right"></i> </li>
							<li><a href="#">新增订单</a></li>
						</ul>
					</div>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
				<form action="/order/createpost" id="form_sample_2" class="form-horizontal">
					<div class="row-fluid">
						<div class="tabbable tabbable-custom tabbable-full-width">
							<ul class="nav nav-tabs">
								<li class="active"><a data-toggle="tab" href="#tab_1_12">基本信息</a></li>
							</ul>

							<div class="form-content">
								<!---->
								<div class="row-fluid margin-bottom-25">
									<div class="span12">
										<!-- BEGIN VALIDATION STATES-->
										<div class="portlet box gdcdc">
											<div class="portlet-body form padding-top-20">
												<!-- BEGIN FORM-->
												<div class="alert alert-error hide">
													<button class="close" data-dismiss="alert"></button>
														您有一些订单填写有误，请认真检查一下
												</div>

												<div class="alert alert-success hide">
													<button class="close" data-dismiss="alert"></button>
													您的订单填写成功！
												</div>

												<div class="control-group">
													<label class="control-label">业务流程<span class="required">*</span></label>
													<div class="controls">
														<select class="span6 m-wrap" name="rule_type">
															<option value=""></option>
															<option value="normal">普通销售</option>
														</select>
													</div>
												</div>

												<div class="control-group">
													<label class="control-label">客户名称<span class="required">*</span></label>
													<div class="controls">
														<select class="span6 m-wrap" name="cust_name" onchange="changesel(this,'change')">
															<option value=""></option>
															<option value="大河马">大河马</option>
														</select>
													</div>
													<input type="hidden" id="cust_id" name="cust_id" value='' />
												</div>
												<!--选客户下拉选择的内容显示-->

												<div class="changesel" id="changeSel">
													<div id="change1" class="hide">
														<!--客户属性-->
														<div class="control-group">
															<label class="control-label">客户属性<span class="required">*</span></label>
															<div class="controls">
																<select class="span6 m-wrap" name="cust_type">
																	@foreach (config('order.order.cust_type') as $cust_type)
																	<option value="{{$loop->index}}">{{$cust_type}}</option>
																	@endforeach
																</select>
															</div>
														</div>
														<div class="control-group">
															<label class="control-label">订单账期<span class="required">*</span></label>
															<div class="controls">
																<select class="span6 m-wrap" name="order_period">
																@foreach (config('order.order.order_period') as $order_period)
																<option value="{{$loop->index}}">{{$order_period}}</option>
																@endforeach
																</select>
															</div>
														</div>
														<!--销售组织*-->
														<div class="control-group">
															<label class="control-label">销售组织<span class="required">*</span></label>
															<div class="controls">
																<select class="span6 m-wrap" name="sales_org">
																	<option value="1">公司运营</option>
																	<option value="2">个体户</option>
																</select>
															</div>
														</div>
														<!--开单账套-->
														<div class="control-group">
															<label class="control-label">开单账套<span class="required">*</span></label>
															<div class="controls">
																<select class="span6 m-wrap" name="create_company">
																	<option value="1">西陇股份</option>
																	<option value="2">上海西陇</option>
																</select>
															</div>
														</div>
														<!--业务人员-->
														<div class="control-group">
															<label class="control-label">业务人员<span class="required">*</span></label>
															<div class="controls">
																<select class="span6 m-wrap" name="clerk">
																	<option value="鹿晗">鹿晗</option>
																	<option value="周杰伦">周杰伦</option>
																</select>
															</div>
														</div>
														<div class="control-group">
															<label class="control-label">所属部门<span class="required">*</span></label>
															<div class="controls">
																<select class="span6 m-wrap" name="clerk_department">
																	<option value="业务部">业务部</option>
																</select>
															</div>
														</div>
														<div class="control-group">
															<label class="control-label">所属片区<span class="required">*</span></label>
															<div class="controls">
																<select class="span6 m-wrap" name="clerk_area">
																	<option value="华东">华东</option>
																</select>
															</div>
														</div>
														<div class="control-group">
															<label class="control-label">销售支持<span class="required">*</span></label>
															<div class="controls">
																<select class="span6 m-wrap" name="sales_support">
																	<option value="海西">海西</option>
																</select>
															</div>
														</div>
														
													</div>
												</div>

												<div class="control-group">
													<label class="control-label">支付方式<span class="required">*</span></label>
													<div class="controls">
														<select class="span6 m-wrap" name="payment">
															<option></option>
															@foreach (config('order.order.payment') as $payment)
																<option value="{{$loop->index}}">{{$payment}}</option>
															@endforeach
														</select>
													</div>
												</div>

												<div class="control-group">
													<label class="control-label">币	  种<span class="required">*</span></label>
													<div class="controls">
														<select class="span6 m-wrap" name="currency">
															@foreach (config('order.order.currency') as $currency)
																<option value="{{$loop->index}}">{{$currency}}</option>
															@endforeach
														</select>
													</div>
												</div>

												<div class="control-group">
													<label class="control-label">发票类型<span class="required">*</span></label>
													<div class="controls" onchange="changesel(this,'fapiao')">
														<label class="radio radiobill line">
															<input type="radio" name="invoice_type" value="1" data-val="增值税专用发票" />增值税专用发票
														</label>

														<label class="radio radiobill line">
															<input type="radio" name="invoice_type" value="2" data-val="增值税普通发票" />增值税普通发票
														</label>
														<label class="radio radiobill line">
															<input type="radio" name="invoice_type" value="0"  checked data-val="不开发票" />不开发票
														</label>
														<span id="form_2_membership_error"></span>
													</div>
												</div>
												<div class="control-group">
													<label class="control-label">是否折让</label>
													<div class="controls">
														<label class="radio radiobill line">
															<input type="radio" name="discount" value="0" checked />否
														</label>

														<label class="radio radiobill line">
															<input type="radio" name="discount" value="1" id="disYes" />是
															<input type="text" class="span8 m-wrap c-detailress" name="remark" placeholder="请输入OA审核编号">
														</label>
														<span id="form_discount_error"></span>
													</div>
												</div>
											</div>		
										<!-- END VALIDATION STATES-->
										</div>
									</div>
								<!--end tab-pane-->
								</div>
							</div>
						<!--end tabbable-->
						</div>
					</div>
					<div class="row-fluid">
						<div class="tabbable tabbable-custom tabbable-full-width">
							<ul class="nav nav-tabs">
								<li class="active"><a data-toggle="tab" href="#tab_1_12">配送信息</a></li>
							</ul>

							<div class="form-content">
								<!---->
								<div class="row-fluid margin-bottom-25">
									<div class="span12">
										<!-- BEGIN VALIDATION STATES-->
										<div class="portlet box gdcdc">
											<div class="portlet-body form padding-top-20">
												
												<div class="control-group">
													<label class="control-label">配送方式<span class="required">*</span></label>
													<div class="controls">
														<select class="span6 m-wrap" name="deliver" onchange="changesel(this,'')">
															<option></option>
															@foreach (config('order.order.deliver') as $deliver)
																<option value="{{$loop->index}}" data-val="{{$loop->index}}">{{$deliver}}</option>
															@endforeach
														</select>
													</div>
												</div>
												<!--下拉选择"非自提"的内容显示-->
												<div class="delivechange" id="deliveryChange">
													<div class="control-group portlet-body clearfix" id="delivery1">
														<label class="control-label">收货地址<span class="required">*</span></label>
														<div class="controls">
															<select class="span6 m-wrap" name="address_id" id="addresskind" >
															</select>
															<div class="btn-group nom10 j-newress" >
																<a href="javascript:;" id="sample_address" class="btn btn-primary">
																 	<i class="icon-plus icon-white"></i>
																	<span>新增地址</span>
																</a>
															</div>
														</div>
													</div>
												</div>

												<div class="control-group">
													<label class="control-label">发货公司<span class="required">*</span></label>
													<div class="controls">
														<select class="span6 m-wrap" name="supplier">
															<option></option>
															@foreach (config('order.order.supplier') as $supplier)
																<option value="{{$loop->index}}" data-val="{{$loop->index}}">{{$supplier}}</option>
															@endforeach
														</select>
													</div>
												</div>
											</div>		
										<!-- END VALIDATION STATES-->
										</div>
									</div>
								<!--end tab-pane-->
								</div>
							</div>
						<!--end tabbable-->
						</div>
					</div>
					<div class="row-fluid">
						<div class="tabbable tabbable-custom tabbable-full-width">
							<ul class="nav nav-tabs">
								<li class="active"><a data-toggle="tab" href="#tab_1_12">自产商品</a></li>
							</ul>

							<div class="form-content">
								<!---->
								<div class="row-fluid margin-bottom-25">
									<div class="span12">
										<!-- BEGIN VALIDATION STATES-->
										<div class="portlet box gdcdc">
											<div class="portlet-body form padding-top-20">
												<div class="control-group">
													<div class="row-fluid margin-bottom-20">
														<div class="span12">
															<!-- BEGIN EXAMPLE TABLE PORTLET-->
															<div class="portlet box light-grey" style="width: 98%; margin: 0 auto">
																<div class="portlet-body">
																	<div class="clearfix">
																		<div class="btn-group">
																			<!--<button id="sample_add_1" class="btn btn-success">
																			新增订单
																			</button>	-->
																			<a href="javascript:;" id="add_product_btn" class="btn btn-success">
																			新增商品
																			</a>
																		</div>
																		<div class="btn-group">
																			<!--<button id="sample_add_1" class="btn btn-success">
																			新增订单
																			</button>	-->
																			<a href="javascript:;" id="select_product" class="btn btn-success">
																			新增商品2
																			</a>
																		</div>

																		<div class="btn-group">
																			<a href="javascript:;" id="del_product_btn" class="btn btn-default">
																			删除
																			</a>
																		</div>
																	</div>
																	<!--  -->
																	<div class="ordertball table-responsive margin-bottom-20">
																	   <table class="table table-bordered tablelist" id="dataTableDetail">
																			<thead class="tbhead">
																				<tr>
																					<th width="28">
																						<label class="lbmargin">
																							<input type="checkbox"class="checkson SelectAllImg"/>
																							<img src="{{URL::asset('static/images/c_checkbox_off.png')}}"/>
																						</label>
																					</th>
																					<th class="t1">
																						<p>库存编码</p>
																					</th>
																					<th class="t1">
																						<p>商品名称</p>
																					</th>
																					<th class="t1">
																						<p>产品属性</p>
																					</th>
																					<th class="t1">
																						<p>规格</p>
																					</th>
																					<th class="t1">
																						<p>单位</p>
																					</th>
																					<th class="t1">
																						<p>数量</p>
																					</th>
																					<th class="t1">
																						<p>含税单价</p>
																					</th>
																					<th class="t1">
																						<p>小计</p>
																					</th>
																				</tr>
																			</thead>
																			<tbody class="tbbody" id="product_list_show">
																				<!--合计-->
																				<tr>
																					<td class="linhigh">
																						<label class="lbmargin">
																						合计
																						</label>
																					</td>
																					<td class="linhigh"></td>
																					<td class="linhigh"></td>
																					<td class="linhigh"></td>
																					<td class="linhigh"></td>
																					<td class="linhigh"></td>
																					<td class="linhigh" id="total_num">0</td>
																					<td class="linhigh"></td>
																					<td class="linhigh" id="total_price">0.00</td>
																				</tr>
																			</tbody>
																	   </table>
																	</div>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>		
										<!-- END VALIDATION STATES-->
										</div>
									</div>
								<!--end tab-pane-->
								</div>
							</div>
						<!--end tabbable-->
						</div>
					</div>

					<div class="row-fluid">
						<div class="tabbable tabbable-custom tabbable-full-width">
							<ul class="nav nav-tabs">
								<li class="active"><a data-toggle="tab" href="#tab_1_12">外采商品</a></li>
							</ul>

							<div class="form-content">
								<!---->
								<div class="row-fluid margin-bottom-25">
									<div class="span12">
										<!-- BEGIN VALIDATION STATES-->
										<div class="portlet box gdcdc">
											<div class="portlet-body form padding-top-20">
												<div class="control-group">
													<div class="row-fluid margin-bottom-20">
														<div class="span12">
															<!-- BEGIN EXAMPLE TABLE PORTLET-->
															<div class="portlet box light-grey" style="width: 98%; margin: 0 auto">
																<div class="portlet-body">
																	<div class="clearfix">
																		<div class="btn-group">
																			<!--<button id="sample_add_1" class="btn btn-success">
																			新增订单
																			</button>	-->
																			<a href="javascript:;" id="add_purchase_product_btn" class="btn btn-success">
																			新增外采商品
																			</a>
																		</div>
																		<div class="btn-group">
																			<a href="javascript:;" id="del_purchase_product_btn" class="btn btn-default">
																			删除
																			</a>
																		</div>
																	</div>
																	<!--  -->
																	<div class="ordertball table-responsive margin-bottom-20">
																	   <table class="table table-bordered tablelist" id="dataTableDetail">
																			<thead class="tbhead">
																				<tr>
																					<th width="28">
																						<label class="lbmargin">
																							<input type="checkbox"class="checkson SelectAllImg"/>
																							<img src="{{URL::asset('static/images/c_checkbox_off.png')}}"/>
																						</label>
																					</th>
																					<th class="t1">
																						<p>库存编码</p>
																					</th>
																					<th class="t1">
																						<p>商品名称</p>
																					</th>
																					<th class="t1">
																						<p>产品属性</p>
																					</th>
																					<th class="t1">
																						<p>规格</p>
																					</th>
																					<th class="t1">
																						<p>单位</p>
																					</th>
																					<th class="t1">
																						<p>数量</p>
																					</th>
																					<th class="t1">
																						<p>含税单价</p>
																					</th>
																					<th class="t1">
																						<p>小计</p>
																					</th>
																				</tr>
																			</thead>
																			<tbody class="tbbody" id="product_list_show">
																				<!--合计-->
																				<tr>
																					<td class="linhigh">
																						<label class="lbmargin">
																						合计
																						</label>
																					</td>
																					<td class="linhigh"></td>
																					<td class="linhigh"></td>
																					<td class="linhigh"></td>
																					<td class="linhigh"></td>
																					<td class="linhigh"></td>
																					<td class="linhigh" id="total_num">0</td>
																					<td class="linhigh"></td>
																					<td class="linhigh" id="total_price">0.00</td>
																				</tr>
																			</tbody>
																	   </table>
																	</div>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>		
										<!-- END VALIDATION STATES-->
										</div>
									</div>
								<!--end tab-pane-->
								</div>
							</div>
						<!--end tabbable-->
						</div>
					</div>
					<div class="row-fluid">
						<div class="tabbable tabbable-custom tabbable-full-width">
							<ul class="nav nav-tabs">
								<li class="active"><a data-toggle="tab" href="#tab_1_12">提交</a></li>
							</ul>

							<div class="form-content">
								<!---->
								<div class="row-fluid margin-bottom-25">
									<div class="span12">
										<!-- BEGIN VALIDATION STATES-->
										<div class="portlet box gdcdc">
											<div class="portlet-body form padding-top-20">
												<div class="control-group">
													<label class="control-label">客户备注</label>
													<div class="controls">
														<input type="text" class="span8 m-wrap c-detailress" name="remark" placeholder="备注">
													</div>
												</div>
												<div class="control-group">
													<label class="control-label">内部备注</label>
													<div class="controls">
														<input type="text" class="span8 m-wrap c-detailress" name="inner_remark" placeholder="备注">
													</div>
												</div>
												<div class="control-group">
													<div class="form-actions">
														<button type="submit" class="btn green">提交</button>
														<button type="button" class="btn" onclick="fomrReset('form_sample_2')">取消</button>
													</div>
												</div>
											</div>		
										<!-- END VALIDATION STATES-->
										</div>
									</div>
								<!--end tab-pane-->
								</div>
							</div>
						<!--end tabbable-->
						</div>
					</div>
				</form>
			</div>
		</div>
	
	<!-- footer -->
	@include('common.footer')

	<!--新增收货地址-->
	<div class="addnewress hide" id="j-addNewress">
		<meta name="csrf-token" content="{{ csrf_token() }}">
		<div class="row-fluid">
			<div class="span12">
				<form action="#" id="form_address" class="form-horizontal padding-top-20" enctype="application/x-www-form-urlencoded">
					<div class="control-group">
						<label class="control-label tanwid">所在区域<span class="required">*</span></label>
						<div class="controls mlft">
							<div class="pick-area-show" name="areakind"></div>
							<input type="hidden" class="c-areakind" placeholder="" />
						</div>
					</div>
					<div class="control-group">
						<label class="control-label tanwid">详细地址<span class="required">*</span></label>
						<div class="controls mlft">
							<input type="text" class="span8 m-wrap c-detailress" autocomplete="off" name="detail" placeholder="请输入详细地址">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label tanwid">收货人姓名<span class="required">*</span></label>
						<div class="controls mlft">
							<input type="text" class="span8 m-wrap c-rename" autocomplete="off" name="name" placeholder="请输入收件人姓名">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label tanwid">手机号码<span class="required">*</span></label>
						<div class="controls mlft">
							<input type="tel" class="span8 m-wrap c-telphone" autocomplete="off" name="mobile"  placeholder="请输入您的手机号">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label tanwid">固定电话<span class=""></span></label>
						<div class="controls mlft">
							<input type="text" class="span8 m-wrap c-landtel" autocomplete="off" name="telphone"  placeholder="请输入您的固定电话">
						</div>
					</div>
					{{-- <div class="form-actions">
						<button type="submit" class="btn green">确定</button>
						<button type="button" class="btn" onclick="closedHandler()">取消</button>
					</div> --}}
				</form>
			</div>
		</div>
	</div>

	<div class="modelhist j-mproChoose hide">
		<div class="row-fluid clearfix">
			<div class="span4">
				<div class="zTreeDemoBackground">
					<ul id="treeDemo" class="ztree"></ul>
				</div>
			</div>

			<div class="span8">
				<div class="showd" id="j-showdPro">
					<div class="row-fluid clearfix">
						<div class="span12">
							<div class="portlet-body margin-right-15">
								<div class="ordertball table-responsive margin-bottom-20  greyground">
									<div class="protitle clearfix">
										<div class="proleft pull-left"> 全部商品</div>
										<div class="proright pull-right">
											<form class="formsearch">
												<div class="inputbox">
													<input type="text" id="product_search_keyword" placeholder="Search..." class="j-serchput">
													<input type="button" class="subseach" id="j-subSeachBtn" value=" ">
												</div>
											</form>
										</div>
									</div>
									<div class="protable">
										<table class="table table-bordered tablelist" id="serchTable" style="background: #fff;">
											<thead class="prot_head">
											<tr class="hedtr">
												<th>
													<p>操作</p>
												</th>
												<th class="t1">
													<p>存货编码</p>
												</th>
												<th class="t1">
													<p>商品名称</p>
												</th>
												<th class="t1">
													<p>规格</p>
												</th>
												<th class="t1">
													<p>单位</p>
												</th>
												<th class="t1">
													<p>可用量</p>
												</th>
											</tr>
											</thead>
											<tbody class="prot_body" id="layerDown">

											</tbody>

										</table>
									</div>
								</div>
								<!--已选商品-->
								<div class="ordertball table-responsive margin-bottom-20 greyground">
									<div class="protitle clearfix">
										<div class="proleft pull-left"> 已选商品</div>
										{{--<div class="proright pull-right">--}}
											{{--<a href="javascript:" class="btn btn-danger j-choosedpro">删除</a>--}}
										{{--</div>--}}
									</div>
									<div>
										<table class="table table-bordered tablelist newList" style="background: #fff;">
											<thead class="choosed_head">
											<tr>
												<th>
													<p>操作</p>
												</th>
												<th class="t1">
													<p>存货编码</p>
												</th>
												<th class="t1">
													<p>商品名称</p>
												</th>
												<th class="t1">
													<p>规格</p>
												</th>
												<th class="t1">
													<p>单位</p>
												</th>
												<th class="t1">
													<p>可用量</p>
												</th>
											</tr>
											</thead>
											<tbody class="choosed_body" id="need_post">

											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>

			</div>
		</div>

	</div>

	<!-- BEGIN PAGE LEVEL PLUGINS -->
	@include('common.validate')

	<script type="text/javascript" src="{{URL::asset('static/js/lib/form-valid-create-order.js')}}?{{$_ENV['static_version']}}"></script>
	<script type="text/javascript" src="{{URL::asset('static/js/public/app.js')}}?{{$_ENV['static_version']}}"></script>
	<link rel="stylesheet" type="text/css" href="{{URL::asset('static/style/lib/pick-pcc.css')}}" />
	<script type="text/javascript" src="{{URL::asset('static/js/lib/pick-pcc.js')}}"></script>
	<!--tree-->
	<script type="text/javascript" src="{{URL::asset('static/js/public/jquery.ztree.core.js')}}"></script>
	<link type="text/css" rel="stylesheet" href="{{URL::asset('static/style/public/zTreeStyle.css')}}" />
	<!--single-->
	<script type="text/javascript" src="{{URL::asset('static/js/lib/model-treelist.js')}}"></script>
	<link  type="text/css" rel="stylesheet" href="{{URL::asset('static/style/lib/model-treelist.css')}}" />
	<!-- END PAGE LEVEL STYLES -->
	<script>
		jQuery(document).ready(function() {
			// initiate layout and plugins
			App.init();
			FormValidation.init();
		});

		var get_addr_by_cust = function(cust_id){
			$.ajax({
				url: "/order/ajaxGetAddrByCust",
				type : "get",
				dataType :"json",
				data:'&cust_id='+cust_id,
				success: function(data){
					$('#addresskind').html('<option></option>');
					for(v in data){
						$('#addresskind').append('<option value="'+data[v].id+'">'+data[v].address+data[v].detail+'</option>');
					}
				},
				error: function(data){
					layer.msg('ERROR!',{icon:2,time:1000});
				}
			});
		}

		var scrollLodingData = false;
		var scrollloadPage = 1;
		$(".protable").scroll(function() {
			var	_this = $(this);
			var leftFooter = _this[0].scrollHeight-_this.scrollTop()-_this.innerHeight()
			if(leftFooter <= 20){
				if(scrollLodingData == false){
					reander_product();
				}
			}
		});
		var reander_product = function(){
			scrollLodingData = true;
			// $.ajaxSetup({
				// async:true,
			// });
			var searchUrl = '/order/ajaxGetProductPriceList?page='+scrollloadPage;
			if($('#product_search_keyword').val()){
				searchUrl += '&key='+$('#product_search_keyword').val();
			}
			$.get(searchUrl, function(res){
				str = '';
				for(k in res.data){
					var item = res.data[k];
					str += '<tr id="tr_'+item.id+'">';
					str += '<td><a href="javascript:add_product(\''+item.id+'\');">添加</a></td>';
					str += '<td data="'+item.danger_type+'">'+item.bn+'</td>';
					str += '<td>'+item.name+'</td>';
					str += '<td>'+item.key_name+'</td>';
					str += '<td>'+item.unit+'</td>';
					str += '<td>'+item.store_count+'</td>';
					str += '</tr>';
				}
				$('#layerDown').append(str);
				scrollloadPage = scrollloadPage+1;
				scrollLodingData = false;
			});
		}
		var add_product = function(id){
			var td = $('#tr_'+id).clone();
			td.find('a').parent().remove();
			str = '';
			str += '<tr id="del_'+id+'">';
			str += '<td><a href="javascript:del_product(\''+id+'\');">删除</a></td>';
			str += td.html();
			str += '</tr>';
			if($('#del_'+id).html() == undefined){
				$('#need_post').append(str);
			}else{
				layer.msg('商品已选择',{icon:2,time:1000});
			}
		}
		var del_product = function(id){
			$('#del_'+id).remove();
		}
		$('#j-subSeachBtn').on('click', function(){
			$('#layerDown').html('');
			scrollloadPage = 1;
			reander_product();
			// get_product_list();
		});
		var select_product_done = function(){
			$('#need_post').find('tr').each(function(){
				create_select_product_done($(this));
			});
		}
		var create_select_product_done = function(_this){
			var goods_price = $(_this).attr('id').substr(4);
			var stock_num;
			var property;
			var name;
			var size;
			var pack;

			var i = 1;
			$(_this).find('td').each(function(){
				if(i == 2){
					stock_num = $(this).html();
					property = $(this).attr('data');
				}
				if(i == 3){
					name = $(this).html();
				}
				if(i == 4){
					size = $(this).html();
				}
				if(i == 5){
					pack = $(this).html();
				}
				i++;
			});
			var params = 'stock_num='+stock_num+'&property='+property+'&name='+name+'&size='+size+'&pack='+pack+'&goods_price='+goods_price;
			var str = '';
			str +='<tr id="'+stock_num+'">';
				str +='<td class="linhigh">';
					str +='<label class="lbmargin">';
						str +='<input type="checkbox" name="product_ids[]" class="checkson checkbox_child"/>';
						str +='<img src="{{URL::asset('static/images/c_checkbox_off.png')}}"/>';
					str +='</label>';
				str +='</td>';
				str +='<td class="linhigh">'+stock_num+'</td>';
				str +='<td class="linhigh">'+name+'</td>';
				str +='<td class="linhigh">'+property+'</td>';
				str +='<td class="linhigh">'+size+'</td>';
	 			str +='<td class="linhigh">'+pack+'</td>';
				str +='<td class="linhigh">';
					str +='<input type="hidden" name="product_obj['+stock_num+']" value="'+params+'">';
					str +='<input placeholder="请输入数量" class="input-control putw1 c-orderid" onkeyup="calculate()" id="num_input" type="text" name="num['+stock_num+']" style="margin-top: 0">';
				str +='</td>';
				str +='<td class="linhigh">';
					str +='<input placeholder="请输入>800.00" class="input-control putw1 c-orderid" onkeyup="calculate()" id="price_input" type="text" name="price['+stock_num+']" style="margin-top: 0">';
				str +='</td>';
				str +='<td class="linhigh" id="sample_price">0.00</td>';
			str +='</tr>';
			$('#product_list_show').prepend(str);
		}
		$('#select_product').on('click', function(){

			layer.open({
				type:1,
				title: '选择商品',
				area:['850px','750px'],
				btn:["确定","取消"],
				scrollbar: false,
				offset: 't',
				//shadeClose:true,
				content:$('.j-mproChoose'),
				yes:function(){
					scrollloadPage = 1;
					select_product_done();
					$('layerDown').html('');
					$('#need_post').html('');
				},
				btn2:function(){
					scrollloadPage = 1;
					$('layerDown').html('');
					$('#need_post').html('');
				},
				cancel:function(){
					scrollloadPage = 1;
					$('layerDown').html('');
					$('#need_post').html('');
				}
			});
			reander_product();
			// get_product_list();
		});

		$('#del_product_btn').on('click', function(){
			$(".tbbody input[type='checkbox']").each(function(i){
				if($(this).attr("checked") == "checked"){
					// alert($(this).parents("tr").find('#tttt').val());
					$(this).parents("tr").remove();
				}
			})

		});
		var calculate = function(){
			var tmpnum = 0;
			var tmpprice = 0;
			var tmptotle = 0;
			var totlenum = 0;
			var totleprice = 0;
			$(".tbbody input[type='checkbox']").each(function(i){
				tmpnum = $(this).parents("tr").find('#num_input').val();
				tmpprice = $(this).parents("tr").find('#price_input').val();
				tmpnum = Number(tmpnum);
				totlenum = totlenum + tmpnum;
				tmpprice = Number(tmpprice);
				tmptotle = tmpnum*tmpprice;
				totleprice = totleprice + tmptotle;
				$(this).parents("tr").find('#sample_price').html(tmptotle);
			})
			$('#total_num').html(totlenum);
			$('#total_price').html(totleprice);
		}
		$('#add_product_btn').on('click', function(){
			// var obj = [{"stock_num":"22222","address":"\u5317\u4eac\u5e02\/\u5317\u4eac\u5e02\/\u4e1c\u57ce\u533a","detail":"zhongshanxli1919"},{"id":2,"address":"\u5c71\u897f\u7701\/\u9633\u6cc9\u5e02\/\u77ff\u533a","detail":"\u4e2d\u5c71\u897f\u9647\u8def2988\u53f7"}];
			// alert(obj);

			var stock_num = Date.parse( new Date())/1000;
			var num = Math.ceil(Math.random()*3);
			if(num == 1){
				var property = '普通';
			}
			if(num == 2){
				var property = '易制爆';
			}
			if(num == 3){
				var property = '易制毒';
			}
			var name = '(易制毒三类）2-丁酮，不销售，>95%';
			var size = 5;
			var standard = 'ml';
			var pack = '箱';
			var level = 'AR';
			var params = 'stock_num='+stock_num+'&property='+property+'&name='+name+'&size='+size+'&standard='+standard+'&pack='+pack+'&level='+level;
			var str = '';
			str +='<tr id="'+stock_num+'">';
				str +='<td class="linhigh">';
					str +='<label class="lbmargin">';
						str +='<input type="checkbox" name="product_ids[]" class="checkson checkbox_child"/>';
						str +='<img src="{{URL::asset('static/images/c_checkbox_off.png')}}"/>';
					str +='</label>';
				str +='</td>';
				str +='<td class="linhigh">'+stock_num+'</td>';
				str +='<td class="linhigh">'+name+'</td>';
				str +='<td class="linhigh">'+property+'</td>';
				str +='<td class="linhigh">'+size+standard+'</td>';
				str +='<td class="linhigh">'+pack+'</td>';
				str +='<td class="linhigh">';
					str +='<input type="hidden" name="product_obj['+stock_num+']" value="'+params+'">';
					str +='<input placeholder="请输入数量" class="input-control putw1 c-orderid" onkeyup="calculate()" id="num_input" type="text" name="num['+stock_num+']" style="margin-top: 0">';
				str +='</td>';
				str +='<td class="linhigh">';
					str +='<input placeholder="请输入>800.00" class="input-control putw1 c-orderid" onkeyup="calculate()" id="price_input" type="text" name="price['+stock_num+']" style="margin-top: 0">';
				str +='</td>';
				str +='<td class="linhigh" id="sample_price">0.00</td>';
			str +='</tr>';
			$('#product_list_show').prepend(str);
		});
		$(".pick-area-show").pickArea({
			"format":"province/city/county", //格式
			"display":"block",	   
			"getVal":function(){
				//这个方法是每次选中一个省、市或者县之后，执行的方法
				//console.log($(".pick-area-hidden").val())
				//console.log($(".pick-area-dom").val())
				var thisdom = $("."+$(".pick-area-dom").val());
				thisdom.next().val($(".pick-area-hidden").val());
			}
		});
	</script>

</body>
</html>